<?php 
// +----------------------------------------------------------------------
// | RXThinkCMF框架 [ RXThinkCMF ]
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 南京RXThinkCMF研发中心
// +----------------------------------------------------------------------
// | 官方网站: http://www.rxthink.cn
// +----------------------------------------------------------------------
// | Author: 牧羊人 <1175401194@qq.com>
// +----------------------------------------------------------------------

namespace app\admin\service;


use app\admin\model\OfCopyright;
use app\common\service\BaseService;
use think\facade\Db;

/**
 * 著作权管理-服务类
 * @author 牧羊人
 * @since: 2021/12/21
 * Class OfCopyrightService
 * @package app\admin\service
 */
class OfCopyrightService extends BaseService
{
    /**
     * 构造函数
     * LevelService constructor.
     */
    public function __construct()
    {
        $this->model = new OfCopyright();
    }
	

    /**
     * 获取数据列表
     * @return array
     * @since 2021/12/21
     * @author 牧羊人
     */
    public function getList()
    {
        $param = request()->param();

        // 查询条件
        $map = [];
        
        // 客户名称
        $customer_name = isset($param['customer_name']) ? trim($param['customer_name']) : '';
        if ($customer_name) {
            $map[] = ['customer_name', 'like', "%{$customer_name}%"];
        }
        $company_id = isset($param['company_id']) ? trim($param['company_id']) : '';
        if ($company_id) {
            $map[] = ['company_id', '=', $company_id];
        }else{            
            $admin_id = session("adminId");
            if($admin_id != 1){         
                $wh_or = [];
                $wh_or[] = ["service_id","=",$admin_id];
                $wh_or[] = ["agent_id","=",$admin_id];
                $wh_or[] = ["peer_id","=",$admin_id];
                $arr_ids = Db::name("of_company")->where('mark',1)->where(function($query) use($wh_or){$query->whereOr($wh_or);})->column("id");
                if(!empty($arr_ids)){
                    $map[] = ['company_id', 'in', $arr_ids];            
                }
            }
        }
        // 合同ID
        $contract_id = isset($param['contract_id']) ? trim($param['contract_id']) : '';
        if ($contract_id) {
            $map[] = ['contract_id', '=', $contract_id];
        }
        // 案件名称
        $case_name = isset($param['case_name']) ? trim($param['case_name']) : '';
        if ($case_name) {
            $map[] = ['case_name', 'like', "%{$case_name}%"];
        }
        $speed = isset($param['speed']) ? trim($param['speed']) : '';
        if ($speed!='') {
            $map[] = ['speed', '=', $speed];
        }

        return parent::getList($map); // TODO: Change the autogenerated stub
    }

                                                
}